#include <iostream>

using namespace std;

const int N = 1e5 + 10;
int a[N];
int n, x;
int main()
{
	cin >> n >> x;
	long long  ret = 0;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i];
		if (a[i - 1] + a[i] > x)
		{
			ret += a[i - 1] + a[i] - x;
			a[i] = x - a[i - 1];
		}
	}
	cout << ret << endl;
	return 0;
}